package ae.pcfc.cldos.online.web.controller.admin.general.inbox.notifications.details;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.SessionStatus;

import ae.pcfc.cldos.online.common.delegate.AdminTaskDelegate;
import ae.pcfc.cldos.online.common.vo.FileVO;
import ae.pcfc.cldos.online.common.vo.notifications.NotificationVO;
import ae.pcfc.cldos.online.web.ViewPath;
import ae.pcfc.cldos.online.web.controller.base.BasePageController;

/**
 * A Controller For Admin Related Tasks (Task , Notifications etc)
 * @author ammar
 *
 */
@Controller
@RequestMapping(value = ViewPath.__ADMIN_NOTIFICTIONS_DETAILS)
public class AdminNotificationDetailsController extends BasePageController {

	@Autowired
	@Qualifier("adminTaskDelegate")
	private AdminTaskDelegate adminTaskDelegate;

	/**
	 * 
	 */
	@RequestMapping(value = "/view.htm", method = RequestMethod.GET)
	public void view() {

	}
	
	@ModelAttribute
	public void populateBreadCrumbs(ModelMap model) {
		breadCrumbsFactoryService.populateNotificationsDtlBreadCrumb(model);
	}
	/**
	 * @param msgId
	 * @param request
	 * @param model
	 * @return
	 */
	@ModelAttribute("NotificationDetail")
	public NotificationVO populateNotificationDetail(@RequestParam String msgId,HttpServletRequest request, ModelMap model){
		NotificationVO notificationVO = new NotificationVO();
		notificationVO = adminTaskDelegate.getNotificationDetail(new Long(encryptionDelegate.decodeAndDecrypt(msgId)));
		for(FileVO fileVO : notificationVO.getFileVOs()){
			fileVO.setEncryptedFileId(encryptionDelegate.encryptAndEncode(fileVO.getId().toString()));
		}
		return notificationVO;
	}
	
	/**
	 * @param request
	 * @param status
	 * @param errors
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/form.htm")
	public String form(
			HttpServletRequest request,
			SessionStatus status,
			BindingResult errors) throws Exception {
		
		return "";
	}
	
}
